package org.rufolfheszele.andpixelbyandpixel;

import java.net.Socket;

import android.graphics.Bitmap;
import android.graphics.Point;

public class MainGameController implements IGameController
{
	public enum SocketEventType
	{
		SOCKET_CONNECTION,
		SOCKET_LOST,
		SOCKET_INPUT,
		SOCKET_OUTPUT,
	};
	
	public MainGameController(MainImageView mainImageView)
	{
		// The initial state is the Idle state
		mGameStateController = new IdleGameStateController(mainImageView);
	}
	
	//
	// Methods inherited from IController
	//
	
	@Override
	public boolean handleTouchDown(Point point)
	{
		return mGameStateController.handleTouchDown(point);
	}

	@Override
	public boolean handleTouchUp(Point point)
	{
		return mGameStateController.handleTouchUp(point);
	}

	@Override
	public boolean handleTouchMove(Point point)
	{
		return mGameStateController.handleTouchMove(point);
	}

	@Override
	public Bitmap getBitmap()
	{
		return mGameStateController.getBitmap();
	}
	
	//
	// Methods inherited from IGameController
	//

	@Override
	public boolean host(String level)
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean join(String host, int portNumber)
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void configurationChange()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void kickOffClient()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void finish(FinishReason finishReason)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void changeState(IGameStateController gameStateController)
	{
		// TODO Auto-generated method stub

	}
	
	//
	// Own methods
	//
	
	public void handleSocketEvent(SocketEventType socketEventType, Socket socket)
	{
		switch(socketEventType)
		{
			case SOCKET_CONNECTION:
				mGameStateController.handleSocketConnection(socket);
				break;
			case SOCKET_LOST:
				mGameStateController.handleSocketLost(socket);
				break;
			case SOCKET_INPUT:
				mGameStateController.handleSocketInput(socket);
				break;
			case SOCKET_OUTPUT:
				mGameStateController.handleSocketOutput(socket);
			default:
				break;
		}
	}
	
	IGameStateController mGameStateController = null;
}
